#!/bin/bash
#------------------#
IP=192.168.1.1
min=3
count=3
#------------------#
i=0
let min=$min*60
while true
do
    sleep $min
    for i in $(seq 1 $count)
    do
        result=`ping $IP -t 5 -w 5|grep ttl|wc -l`
        if [ $result == 0 ];then
            echo `date`": Disconnect." >> /var/log/Connection.log
            let i=$i+1
            if [ $i == $count ];then
                echo `date`": Now shutdown." >> /var/log/Connection.log
                i=0
                shutdown -h now
            fi
        else
            echo `date`": connected."
        fi
        sleep $min
    done
done

